#! /usr/bin/env python
# coding:utf-8
import json
import sys

import function

reload(sys)
sys.setdefaultencoding('utf8')
def out_grade():
    try:
        file_name = raw_input('请输入导出的文件名称：')
        stu_file = open(file_name+'.txt', 'w+')
        function.cursor.execute('SELECT * FROM studata')
        stu_grade = function.cursor.fetchall()
        grade_con = json.dumps(stu_grade, encoding='UTF-8', ensure_ascii=False)  # 将元组转化成json，使得输出不出现乱码
        stu_file.write(grade_con)
        print '导出文件成功，文件名为', stu_file.name
        stu_file.close()
    except (TypeError, EOFError, NameError, IOError, SyntaxError, ValueError):
        print '文件导出错误！！'